package com.example.neusoft.zyfypt_wk.model;


import com.example.neusoft.zyfypt_wk.bean.ProjectBean;
import com.example.neusoft.zyfypt_wk.bean.TcaseBean;
import com.example.neusoft.zyfypt_wk.iface.ProjectListener;
import com.example.neusoft.zyfypt_wk.iface.Projectiface;
import com.example.neusoft.zyfypt_wk.iface.TcaseListener;
import com.example.neusoft.zyfypt_wk.iface.Tcaseiface;
import com.example.neusoft.zyfypt_wk.service.ProjectService;
import com.example.neusoft.zyfypt_wk.service.TcaseService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Neusoft on 2017/4/20.
 */
//model  获取项目数据
public class ProjectModel implements Projectiface {
    private Retrofit retrofit;
    private String BASEURL
            ="http://amicool.neusoft.edu.cn/";
     //构造函数
    public ProjectModel()
    {   //使用Retrofit----1
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    //获取数据
    @Override
    public void getResultList(String mod, int page, String sessionID, final ProjectListener listener) {
        //使用Retrofit----2
        ProjectService service
                =retrofit.create(ProjectService.class);
        Call<List<ProjectBean>> call
                =service.getResult(mod,page,sessionID);
        //使用Retrofit----3
        call.enqueue(new Callback<List<ProjectBean>>() {
            @Override
            public void onResponse(Call<List<ProjectBean>> call, Response<List<ProjectBean>> response) {
                if(response.isSuccessful() && response!=null)
                {  listener.onResponse(response.body());
                }
                else   listener.onFail("onresponse fail");
            }
            @Override
            public void onFailure(Call<List<ProjectBean>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });



    }
}
